package newx.com.control.text
{
	import flash.filters.BitmapFilterQuality;
	import flash.filters.GlowFilter;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	
	import newx.com.NxUIComponent;
	import newx.com.config.StaticIni;
	import newx.com.control.ILabel;
	import newx.utils.DrawAPI;
	
	public class NxLabel extends NxUIComponent implements ILabel
	{
		private var _text			:String;
		
		private var _color 		:uint = 0xffa800;
		
		private var _textField 	:TextField;
		
		private var _html			:Boolean;
		
		private var _format		:TextFormat = new TextFormat();
		
		private var _glow			:GlowFilter;
		
		public static var  glow:GlowFilter		= 	new GlowFilter(0x000000, 1, 2, 2, 3, BitmapFilterQuality.LOW);

		public function NxLabel()
		{
			super();
			
			_textField = new TextField();
			_textField.mouseEnabled = false;
			_textField.multiline = true;
			_textField.wordWrap = false;
			_textField.textColor = 0xffa800;
			_textField.autoSize	= TextFieldAutoSize.LEFT;
			
			addChild(_textField);
			
			glowColor = parseInt(StaticIni.getIniVar("Css_control_nxLabel", "glowColor"));
			
		}
		
		private function draw() : void
		{
			clearAll();
			
			this.addChild(DrawAPI.getLabelBitmap(_textField));
		}
		
		private function clearAll() : void
		{
			while(numChildren > 0)
			{
				removeChildAt(0);
			}
		}
		
		public function get condenseWhite():Boolean
		{
			return _textField.condenseWhite;
		}
		
		public function set condenseWhite(val:Boolean):void
		{
			_textField.condenseWhite;
		}
		
		/**
		 *	废弃接口，以后劲量不用 
		 */
		public function set htmlStrByBorder(val:String):void
		{
			_html = true;
			
			_textField.htmlText = val;
			
			draw();
		}
		
		public function set glowColor( value : int ):void
		{
			_glow = new GlowFilter(value, 1, 2, 2, 3, BitmapFilterQuality.LOW);
			
			_textField.filters = [_glow];
			
			draw();
		}
		
		public function get glowColor():int
		{
			return _glow.color;
		}
		
		public function get htmlText():String
		{
			return _textField.htmlText;
		}
		
		public function set htmlText(val:String):void
		{
			_html = true;
			
			_textField.htmlText = val;
			
			draw();
		}
		
		public function get text():String
		{
			return _textField.text;
		}
		
		public function set text(val:String):void
		{
			_html = false;
			
			_textField.text = val;
			
			txtFilters = [ glow ];

			draw();
		}
		
		public function get txtFilters():Array
		{
			return _textField.filters;
		}
		
		public function set txtFilters(val:Array):void
		{
			_textField.filters = val;
	
			draw();
		}
		
		public function getTextFormat(beginIndex:int=-1, endIndex:int=-1):TextFormat
		{
			return _textField.getTextFormat(beginIndex, endIndex);
		}
		
		public function setTextFormat(format:TextFormat, beginIndex:int=-1, endIndex:int=-1):void
		{
			
			NxTextFormatManager.setFormatToOld(format,_format);
			NxTextFormatManager.updataTextFormat(_textField,_format,beginIndex,endIndex);			
			draw();
		}
		
		public function get color():uint
		{
			return _color;
		}
		
		public function set color(value:uint):void
		{
			_color	= value;
			_textField.textColor = _color;
			
			if(_html)
			{
				htmlText = htmlText;
			}
			else
			{
				text = text;
			}
		}
		
		private function getGlowFilter():GlowFilter
		{
//			var glow:GlowFilter		= 	new GlowFilter();
//			glow.color 				= 	0x000000;
//			glow.alpha 				= 	1;
//			glow.blurX 				=	2;
//			glow.blurY				= 	2;
//			glow.strength			=	4;
//			glow.quality			= 	BitmapFilterQuality.HIGH;
			return glow;
			
			//		private static var  glow:GlowFilter		= 	new GlowFilter(0x000000, 1, 2, 2, 3, BitmapFilterQuality.LOW);

		}
		
		/**
		 *	废弃接口 
		 */
		public function set htmlStr(val:String):void
		{
			htmlText = val;
		}
		
		/**
		 *	废弃接口 
		 */
		public function get htmlStr():String
		{
			return text;
		}
		
		override public function get width():Number
		{
			return _textField.textWidth;
		}
		
		override public function set width(value:Number):void
		{
			return;
		}
		
		override public function get height():Number
		{
			return _textField.height;
		}
		
		override public function set height(value:Number):void
		{
			return;
		}

		public function get textField():TextField
		{
			return _textField;
		}

		
	}
}